﻿
@{
    ViewData["Title"] = "LogList";
    Layout = "~/Areas/Admin/Views/_Layout.cshtml";
}

<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        @*<button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>*@
        <button class="layui-btn layui-btn-sm" onclick="javascript:location.replace(location.href);">刷新</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
        var Name = getParam('name');
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#test'
                , height: 'full-20'
                , url: '/home/GetOneLog?name=' + Name
                , toolbar: '#toolbarDemo'
                , title: 'IIS访问日记'
                , cols: [[
                    { type: 'checkbox', fixed: 'left' }
                    , { field: 'cIp', title: 'IP', fixed: 'left', unresize: true, sort: true }
                    , {
                        field: 'csUriStem', title: '地址', width: 350, unresize: false, templet: function (res){
                             return Find(res.csUriStem);
                        }
                    }
                    , { field: 'csUriQuery', title: 'URL参数', sort: true,unresize: false }
                    , { field: 'sPort', title: '端口', unresize: false }
                    , { field: 'scStatus', title: '状态', unresize: false }
                    , {
                        field: 'dateTimeEvent', title: '时间'
                    }
                    , {
                        field: 'csMethod', title: '提交方式'
                    }
                    , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150, unresize: false }
                ]]
                , limits: [10, 15, 40, 60, 200,400,1000,2000]
                , limit: 100 //默认采用10
                , page: true
                , request: {
                    pageName: 'pageNumber' //页码的参数名称，默认：page
                    ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
            });

            //头工具栏事件
            table.on('toolbar(test)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'getCheckData':
                        var data = checkStatus.data;
                        layer.alert(JSON.stringify(data));
                        break;
                    case 'getCheckLength':
                        var data = checkStatus.data;
                        layer.msg('选中了：' + data.length + ' 个');
                        break;
                    case 'isAll':
                        layer.msg(checkStatus.isAll ? '全选' : '未全选');
                        break;
                };
            });
            //监听行工具事件
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                //console.log(obj)
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        obj.del();
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    layer.prompt({
                        formType: 2
                        , value: data.email
                    }, function (value, index) {
                        obj.update({
                            email: value
                        });
                        layer.close(index);
                    });
                }
            });
        });
        var systemKeyWords = ['app', 'admincenter', 'plugin']
        function Find(key)
        {
            var isFind = false;
            systemKeyWords.forEach(function (item) {
                if (key.indexOf(item) != -1)
                {
                    isFind = true;
                }
            })
            return isFind ? '<span style="color:red">' + key + '</span>' : key
        }

        function getParam(paramName) {
            paramValue = "", isFound = !1;
            if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
                arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
                while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
            }
            return paramValue == "" && (paramValue = null), paramValue
        }
</script>

